package com.ziyun.erp.modules.goodsCategory.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ziyun.erp.modules.goodsCategory.dao.GoodsCategoryRelationDao;
import com.ziyun.erp.modules.goodsCategory.entity.GoodsCategoryRelationEntity;
import com.ziyun.erp.modules.goodsCategory.service.GoodsCategoryRelationService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;


@Service("goodsCategoryRelationService")
public class GoodsCategoryRelationServiceImpl extends ServiceImpl<GoodsCategoryRelationDao, GoodsCategoryRelationEntity> implements GoodsCategoryRelationService {

    @Autowired
    private GoodsCategoryRelationDao goodsCategoryRelationDao;

    @Override
//    @DataSource(name = DataSourceNames.SECOND)
    public PageUtils queryPage(Map<String, Object> params) {
        Page<GoodsCategoryRelationEntity> page = this.selectPage(
                new Query<GoodsCategoryRelationEntity>(params).getPage(),
                new EntityWrapper<GoodsCategoryRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
//    @DataSource(name = DataSourceNames.SECOND)
    public GoodsCategoryRelationEntity getByCategoryId(Integer categoryId) {
        GoodsCategoryRelationEntity goodsCategoryRelationEntity = goodsCategoryRelationDao.selectByCategoryId(categoryId);
        return goodsCategoryRelationEntity;
    }

    @Override
//    @DataSource(name = DataSourceNames.SECOND)
    public int updateByGoodsCategoryId(GoodsCategoryRelationEntity goodsCategoryRelationEntity) {
        return this.baseMapper.update(goodsCategoryRelationEntity,new EntityWrapper<GoodsCategoryRelationEntity>().eq("category_id",goodsCategoryRelationEntity.getCategoryId()));
    }

    @Override
    public BigDecimal getCommissionByGoodsId(Integer goodsId) {
        return baseMapper.getCommissionByGoodsId(goodsId);
    }

}
